package ceshi;

import java.io.*;

public class Demo01 {
    public static void main(String[] args) throws IOException {
        //以前都需要一个文本路径，又学到了
        //BufferedReader br = new BufferedReader(new FileReader("aaa.txt"))//关联aaa.txt
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //System.in输入的是字节要用InputStreamReader转换为字符传给    BufferedReader
        //Scanner scan=new Scanner(System.in);
        //String s=scan.next()


        String path="E:\\wenjian\\a.txt";

        File file = new File(path);

        //创建文件路径 E:\wenjian

        System.out.println(file.getParentFile());   //  E:\wenjian

        if(!file.getParentFile().exists()){
            file.getParentFile().mkdirs();
        }

        //写入流会自动创建   a.txt文件
        BufferedWriter bw = new BufferedWriter(new FileWriter(path, true));   //true  追加输入


        while (true) {
            System.out.println("请输入:");
            String s = br.readLine();

            if ("quit".equals(s)) {
                break;
            }
            bw.write(s);
            bw.newLine();
        }
        bw.close();
        br.close();
    }
}
